1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module sourceview.Completion;
26 
27 private import glib.Str;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import pango.PgAttributeList;
31 private import sourceview.Buffer;
32 private import sourceview.CompletionProviderIF;
33 private import sourceview.View;
34 private import sourceview.c.functions;
35 public  import sourceview.c.types;
36 private import std.algorithm;
37 
38 
39 /**
40  * Main Completion Object.
41  * 
42  * The completion system helps the user when they writes some text,
43  * such as words, command names, functions, and suchlike. Proposals can
44  * be shown, to complete the text the user is writing. Each proposal can
45  * contain an additional piece of information (for example
46  * documentation), that is displayed when the "Details" button is
47  * clicked.
48  * 
49  * Proposals are created via a [iface@CompletionProvider]. There can
50  * be for example a provider to complete words (see [class@CompletionWords]),
51  * another provider for the completion of
52  * function names, etc. To add a provider, call
53  * [method@Completion.add_provider].
54  * 
55  * When several providers match, they are all shown in the completion
56  * window, but one can switch between providers: see the
57  * #GtkSourceCompletion::move-page signal. It is also possible to
58  * activate the first proposals with key bindings, see the
59  * #GtkSourceCompletion:accelerators property.
60  * 
61  * The [iface@CompletionProposal] interface represents a proposal.
62  * 
63  * If a proposal contains extra information (see
64  * %GTK_SOURCE_COMPLETION_COLUMN_DETAILS), it will be
65  * displayed in a supplemental details window, which appears when
66  * the "Details" button is clicked.
67  * 
68  * Each [class@View] object is associated with a [class@Completion]
69  * instance. This instance can be obtained with
70  * [method@View.get_completion]. The [class@View] class contains also the
71  * [signal@View::show-completion] signal.
72  * 
73  * A same [iface@CompletionProvider] object can be used for several
74  * `GtkSourceCompletion`'s.
75  */
76 public class Completion : ObjectG
77 {
78 	/** the main Gtk struct */
79 	protected GtkSourceCompletion* gtkSourceCompletion;
80 
81 	/** Get the main Gtk struct */
82 	public GtkSourceCompletion* getCompletionStruct(bool transferOwnership = false)
83 	{
84 		if (transferOwnership)
85 			ownedRef = false;
86 		return gtkSourceCompletion;
87 	}
88 
89 	/** the main Gtk struct as a void* */
90 	protected override void* getStruct()
91 	{
92 		return cast(void*)gtkSourceCompletion;
93 	}
94 
95 	/**
96 	 * Sets our main struct and passes it to the parent class.
97 	 */
98 	public this (GtkSourceCompletion* gtkSourceCompletion, bool ownedRef = false)
99 	{
100 		this.gtkSourceCompletion = gtkSourceCompletion;
101 		super(cast(GObject*)gtkSourceCompletion, ownedRef);
102 	}
103 
104 
105 	/** */
106 	public static GType getType()
107 	{
108 		return gtk_source_completion_get_type();
109 	}
110 
111 	/**
112 	 * This will add `<b>` tags around matched characters in @haystack
113 	 * based on @casefold_query.
114 	 *
115 	 * Params:
116 	 *     haystack = the string to be highlighted
117 	 *     casefoldQuery = the typed-text used to highlight @haystack
118 	 *
119 	 * Returns: a #PangoAttrList or %NULL
120 	 */
121 	public static PgAttributeList fuzzyHighlight(string haystack, string casefoldQuery)
122 	{
123 		auto __p = gtk_source_completion_fuzzy_highlight(Str.toStringz(haystack), Str.toStringz(casefoldQuery));
124 
125 		if(__p is null)
126 		{
127 			return null;
128 		}
129 
130 		return ObjectG.getDObject!(PgAttributeList)(cast(PangoAttrList*) __p, true);
131 	}
132 
133 	/**
134 	 * This helper function can do a fuzzy match for you giving a haystack and
135 	 * casefolded needle.
136 	 *
137 	 * Casefold your needle using [func@GLib.utf8_casefold] before
138 	 * running the query.
139 	 *
140 	 * Score will be set with the score of the match upon success. Otherwise,
141 	 * it will be set to zero.
142 	 *
143 	 * Params:
144 	 *     haystack = the string to be searched.
145 	 *     casefoldNeedle = A g_utf8_casefold() version of the needle.
146 	 *     priority = An optional location for the score of the match
147 	 *
148 	 * Returns: %TRUE if @haystack matched @casefold_needle, otherwise %FALSE.
149 	 */
150 	public static bool fuzzyMatch(string haystack, string casefoldNeedle, out uint priority)
151 	{
152 		return gtk_source_completion_fuzzy_match(Str.toStringz(haystack), Str.toStringz(casefoldNeedle), &priority) != 0;
153 	}
154 
155 	/**
156 	 * Adds a [iface@CompletionProvider] to the list of providers to be queried
157 	 * for completion results.
158 	 *
159 	 * Params:
160 	 *     provider = a #GtkSourceCompletionProvider
161 	 */
162 	public void addProvider(CompletionProviderIF provider)
163 	{
164 		gtk_source_completion_add_provider(gtkSourceCompletion, (provider is null) ? null : provider.getCompletionProviderStruct());
165 	}
166 
167 	/** */
168 	public void blockInteractive()
169 	{
170 		gtk_source_completion_block_interactive(gtkSourceCompletion);
171 	}
172 
173 	/**
174 	 * Gets the connected [class@View]'s [class@Buffer]
175 	 *
176 	 * Returns: A #GtkSourceBuffer
177 	 */
178 	public Buffer getBuffer()
179 	{
180 		auto __p = gtk_source_completion_get_buffer(gtkSourceCompletion);
181 
182 		if(__p is null)
183 		{
184 			return null;
185 		}
186 
187 		return ObjectG.getDObject!(Buffer)(cast(GtkSourceBuffer*) __p);
188 	}
189 
190 	/** */
191 	public uint getPageSize()
192 	{
193 		return gtk_source_completion_get_page_size(gtkSourceCompletion);
194 	}
195 
196 	/**
197 	 * Gets the [class@View] that owns the [class@Completion].
198 	 *
199 	 * Returns: A #GtkSourceView
200 	 */
201 	public View getView()
202 	{
203 		auto __p = gtk_source_completion_get_view(gtkSourceCompletion);
204 
205 		if(__p is null)
206 		{
207 			return null;
208 		}
209 
210 		return ObjectG.getDObject!(View)(cast(GtkSourceView*) __p);
211 	}
212 
213 	/**
214 	 * Emits the "hide" signal.
215 	 *
216 	 * When the "hide" signal is emitted, the completion window will be
217 	 * dismissed.
218 	 */
219 	public void hide()
220 	{
221 		gtk_source_completion_hide(gtkSourceCompletion);
222 	}
223 
224 	/**
225 	 * Removes a [iface@CompletionProvider] previously added with
226 	 * [method@Completion.add_provider].
227 	 *
228 	 * Params:
229 	 *     provider = a #GtkSourceCompletionProvider
230 	 */
231 	public void removeProvider(CompletionProviderIF provider)
232 	{
233 		gtk_source_completion_remove_provider(gtkSourceCompletion, (provider is null) ? null : provider.getCompletionProviderStruct());
234 	}
235 
236 	/** */
237 	public void setPageSize(uint pageSize)
238 	{
239 		gtk_source_completion_set_page_size(gtkSourceCompletion, pageSize);
240 	}
241 
242 	/**
243 	 * Emits the "show" signal.
244 	 *
245 	 * When the "show" signal is emitted, the completion window will be
246 	 * displayed if there are any results available.
247 	 */
248 	public void show()
249 	{
250 		gtk_source_completion_show(gtkSourceCompletion);
251 	}
252 
253 	/** */
254 	public void unblockInteractive()
255 	{
256 		gtk_source_completion_unblock_interactive(gtkSourceCompletion);
257 	}
258 
259 	/**
260 	 * The "hide" signal is emitted when the completion window should
261 	 * be hidden.
262 	 */
263 	gulong addOnHide(void delegate(Completion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
264 	{
265 		return Signals.connect(this, "hide", dlg, connectFlags ^ ConnectFlags.SWAPPED);
266 	}
267 
268 	/**
269 	 * The "provided-added" signal is emitted when a new provider is
270 	 * added to the completion.
271 	 *
272 	 * Params:
273 	 *     provider = a #GtkSourceCompletionProvider
274 	 */
275 	gulong addOnProviderAdded(void delegate(CompletionProviderIF, Completion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
276 	{
277 		return Signals.connect(this, "provider-added", dlg, connectFlags ^ ConnectFlags.SWAPPED);
278 	}
279 
280 	/**
281 	 * The "provided-removed" signal is emitted when a provider has
282 	 * been removed from the completion.
283 	 *
284 	 * Params:
285 	 *     provider = a #GtkSourceCompletionProvider
286 	 */
287 	gulong addOnProviderRemoved(void delegate(CompletionProviderIF, Completion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
288 	{
289 		return Signals.connect(this, "provider-removed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
290 	}
291 
292 	/**
293 	 * The "show" signal is emitted when the completion window should
294 	 * be shown.
295 	 */
296 	gulong addOnShow(void delegate(Completion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
297 	{
298 		return Signals.connect(this, "show", dlg, connectFlags ^ ConnectFlags.SWAPPED);
299 	}
300 }